#!/usr/bin/env python
# encoding: utf-8

print "cwsavevoice"

# built-in stuff
import unittest
import os
import time
# stuff to test
import sys
sys.path.append("../")
from cwsavevoice import *

class CwsavevoiceTest(unittest.TestCase):
	
	def testFileManagement(self):
		env = {
			"prefs": {
				"speechCommandLine": "cat %(input)s.txt > %(output)s2.txt",
				"speechTextOutputEncoding": "utf8",
				"archiveDirectory": ".",
			},
			"constants": {
				"workingDirectory": ".",
			},
			"static": {
				"cw_archiveTimeFormat": "",
				"cwSaveVoice_archiveName": "test-audio%s%s",
				"cwSaveVoice_successMessage": "%s",
			},
			"context": {
				"selection": u"Ceci est un échantillon"
			}
		}
		today = time.strftime("%Y-%m-%d")
		self.assertEqual(dict(main(env))["messageBox"],os.path.join(".",today,"test-audio"))
		self.assertEqual(codecs.open(os.path.join(".",today,"test-audio2.txt"),"r","utf8").read(),u"Ceci est un échantillon")
		self.assert_(not os.path.exists(os.path.join(".",today,"test-audio.txt")))
		os.remove(os.path.join(".",today,"test-audio2.txt"))
		os.rmdir(os.path.join(".",today))

if __name__ == '__main__':
	unittest.main()


